#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;

  struct ListNode {
     int val;
      struct ListNode *next;
  };


  
int* reverseBookList(struct ListNode* head, int* returnSize)
{
    int len = 0;
    struct ListNode* newhead = NULL;
    struct ListNode* cur = head;
    while (cur)
    {
        struct ListNode* curnext = cur->next;
        cur->next = newhead;
        newhead = cur;
        cur = curnext;
        len++;
    }
    *returnSize = len;

    int* arr = (int*)malloc(sizeof(int) * len);
    for (int i = 0; i < len; i++)
    {
        arr[i] = newhead->val;
        newhead = newhead->next;
    }
    return arr;
}